# OS Environment:wq

ARCH := $(shell uname -m)
CC = gcc
OS := $(shell uname -s)

GNUSTEP_HOME = /opt/GNUstep/Local/Library

# Flags
DEBUG_FLAGS = -g
DEF_FLAGS = -D${ARCH} -D${OS}
MISC_FLAGS = -std=c99
OPT_FLAGS = -O3
#WARN_FLAGS = -pedantic -Wall

# Project
C_DIR = ../c
LIBDIR = build/lib
LIBNAME = libpromoteobjc-${ARCH}.a
HEADERS = \
    src/common/PMTCommonType.h \
    src/containers/PMTFixedQueue.h \
    src/containers/PMTMutableSinglyLinkedList.h \
    src/containers/PMTSinglyLinkedList.h \
    src/memory/PMTAllocator.h \
    src/memory/PMTStandardAllocator.h \
    src/time/PMTStopWatch.h
INCLUDES = -Isrc -Isrc/common -Isrc/containers -Isrc/memory -Isrc/numeric -Isrc/time -Isrc/utils -I${GNUSTEP_HOME}/Headers -I${C_DIR}/include
OBJDIR = build/obj
OBJS = \
    common/PMTCommonType.o \
    containers/PMTFixedQueue.o \
    containers/PMTMutableSinglyLinkedList.o \
    containers/PMTSinglyLinkedList.o \
    memory/PMTStandardAllocator.o \
    time/PMTStopWatch.o
OBJDIROBJS = ${addprefix ${OBJDIR}/, ${OBJS}}

all: install

clean: 
	@echo -e "\033[7m[Cleaning...]\033[0m"
	rm -f ${OBJDIROBJS} ${LIBNAME} ${LIBDIR}/${LIBNAME} include/*

install: lib
	@echo -e "\033[7m[Installing...]\033[0m"
	cp ${HEADERS} include/

lib: compile_echo ${OBJDIROBJS}
	@echo -e "\033[7m[Creating library...]\033[0m"
	ar rcs ${LIBDIR}/${LIBNAME} ${OBJDIROBJS}

compile_echo:
	@echo -e "\033[7m[Compiling...]\033[0m"

${OBJDIR}/%.o: src/%.m ${HEADERS}
	${CC} ${DEBUG_FLAGS} ${DEF_FLAGS} ${MISC_FLAGS} ${OPT_FLAGS} ${WARN_FLAGS} ${INCLUDES} -c src/$*.m -o $@

.PHONY: all clean

